<style scoped>
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
sub,
sup,
tt,
var,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
    -webkit-user-select: none;
            user-select: none;
    -webkit-tap-highlight-color: transparent;
}
a[href^="javascript"]{-webkit-touch-callout: none;}

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
    display: block;
}

body {
    line-height: 1;
}

ol,
ul {
    list-style: none;
}

blockquote,
q {
    quotes: none;
}

blockquote:before,
blockquote:after,
q:before,
q:after {
    content: ' ';
    content: none;
}

table {
    border-collapse: collapse;
    border-spacing: 0;
}

body {
    font: 13px/1.5 Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Noto Sans CJK SC, WenQuanYi Micro Hei, Arial, sans-serif;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: normal;
}

input {
    outline: 0;
}

.hidden {
    float: left;
    width: 0;
    height: 0;
    overflow: hidden;
}

.hiddenText {
    text-indent: 100%;
    white-space: nowrap;
    overflow: hidden;
}

.none {
    display: none;
}

.bold {
    font-weight: bold;
}

.center {
    text-align: center;
}

.clearfix:before,
.clearfix:after {
    content: "";
    display: table;
}

.clearfix:after {
    clear: both;
}

.clearfix {
    zoom: 1;
}

table {
    margin-left: 1px;
}

table td,
table th {
    padding: 5px 10px;
    border: 1px solid #ccc;
    vertical-align: middle;
}

a {
    text-decoration: none;
    color: #000;
}

* {
    box-sizing: border-box;
}

    html {
  width: 100%;
  height: 100%;
}
#loginId {
  width: 100%;
  height: 100%;
  background: url('/src/images/assets/background/logginBg.png') no-repeat;
  background-size: cover;
  margin-top: -10%;
}
.app-main{
    margin: 0;
    padding: 0;
}
/* 头部logo和标题部分 */
header {
  width: 100%;
  height: 182px;
  text-align: center;
  margin-top: 10%;
  /* border: 1px solid #666; */
}
header .logo {
  display: block;
  width: 105px;
  height: 85px;
  background: url('/src/images/assets/icon/login_symbol.png') no-repeat;
  margin: 0 auto;
  margin-top: 80px;
  /* border: 1px solid #667; */
  margin-bottom: 25px;
}
header .title {
    font-size: 32px;
    color: #e0e4e7;
    font-weight: 600;
    /* border: 1px solid #777; */
    /* -webkit-text-stroke:1px #fff; */
    /* text-shadow: 0 0 4px #fff; */
}
/* 登陆部分 */
section {
  width: 360px;
  height: 288px;
  background-color: #4dffff;
  padding-top: 43px;
  margin: 0 auto;
  border-radius: 8px;
  position: relative;
  background: transparent;
  background:rgba(255,244,244,0.3);
  text-shadow: 0 0 4px #fff;
  /* box-shadow:-1px 0px 2px #fff,0px -1px 2px #fff,0px 1px 2px #fff,1px 0px 2px #fff; */
  box-shadow:0px 0px 8px #fff;
  /* opacity:0.5; */
}
section .loggin {
  width: 240px;
  margin: 0 auto;
}
section .loggin .user {
  position: absolute;
  width: 56px;
  height: 42px;
  background: url('/src/images/assets/icon/user.png') 18px 11px no-repeat;
  border: 1px solid #eeeeee;
  border-right: none;
  border-radius: 5px 0 0 5px;
}
section .loggin .password {
  position: absolute;
  width: 56px;
  height: 42px;
  background:  url('/src/images/assets/icon/lock.png') 18px 11px no-repeat;
  border: 1px solid #eeeeee;
  border-right: none;
  border-radius: 5px 0 0 5px;
}
section .loggin input{
  width: 80%;
  height: 42px;
  margin-bottom: 20px;
  border: none;
  border-radius: 0 5px 5px 0;
  /* background-color: #fff; */
  border: 1px solid #eeeeee;
  border-left: none;
  background: #fff;
  font-size: 12px;
  color: #fff;
  padding-left: 8px;
  margin-left: 50px;
  background: transparent;
  /* background:rgba(24,244,244,0.1); */
}

section .loggin button {
  position: absolute;
  width: 240px;
  height: 50px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background-color: #0181d4;
  margin-top: 20px;

  font-size: 20px;
  text-align: center;
  color: #fff;
  letter-spacing: 16px;
  text-indent: 16px;
}

</style>

<template>
    <div id="loginId">
        <header>
            <i class="logo"></i>
            <span class="title">应用统一管控平台</span>
        </header>
        <section>
            <div class="loggin">
                <el-form  :model="formData">
                <i class="user"></i><input type="text" v-model="formData.username" :autofocus="true" required placeholder="用户名"  >
                <i class="password"></i><input type="password" name="password" required placeholder="密 码" v-model="formData.password" @keyup.enter.native="doSubmit" >
                </el-form>
                <el-button type="primary" @click="doSubmit">登录</el-button>
                <!-- <button  @click="doSubmit" >登录</button> -->
            </div>
        </section>

        <!-- <h1>login page</h1>
        <div style="margin: 30px;"></div>
        <el-form label-position="left" label-width="110px" :model="formData">
            <el-form-item label="用户名：admin">
                <el-input v-model="formData.username" :autofocus="true"></el-input>
            </el-form-item>
            <el-form-item label="密码：admin" >
                <el-input v-model="formData.password" @keyup.enter.native="doSubmit"></el-input>
            </el-form-item>
        </el-form>
        <el-button type="primary" @click="doSubmit">login</el-button> -->

    </div>
</template>


<script>
    
    import {zuulHost,uamServer,clientID,authHost,tokenUri,getToken,initDictionaryList,webHost} from '../../api/api';
    import utils from '../../api/utils.js';
    // import '../../api/css/loginbase.css';
    setTimeout(function(){
        location.href= webHost+'#/loginSecond';
    },10);
    
    export default {
        data() {
            return {
                formData: {
                    username: 'admin'
                    ,password: 'admin'
                    ,grant_type: 'password'
                }
            };
        },
        methods: {
            doSubmit:function () {
                var _this=this;
                getToken("username="+this.formData.username+"&password="+this.formData.password+"&grant_type="+this.formData.grant_type)
                    .then(res=>{
                        console.log(res);
                        localStorage.token = res.data.access_token;
                        localStorage.retoken = res.data.refresh_token;
                        // 初始化api管理的权限信息  用ajax同步请求 每次登入获取权限信息
                        _this.$jq.ajax({
                            type : "POST", //提交方式
                            url : zuulHost+"/uaa/roleApiPermission/searchByRole?access_token="+localStorage.token,//路径
                            data : "{}",
                            contentType: "application/json", // 请求数据格式(json)
                            async: false, // 同步
                            datatype: "json", // 返回数据格式(json)
                            headers: {"Content-Type":"application/json"},
                            success : function(result) {//返回数据根据结果进行相应的处理
                                if ( result.code === "S100101" ) {
                                    let json = JSON.stringify(result.data);
                                    localStorage.apiPermission = json;
                                    console.log(json);
                                } else {
                                    console.log("api权限获取失败！");
                                }
                            }
                        });
                        // 初始化字典
                        if(!sessionStorage.allDictData||sessionStorage.allDictData=='[]'||utils.isEmpty(JSON.parse(sessionStorage.allDictData))){
                            let params2 = {
                                data:{isPageAble: false},
                                access_token:"?access_token="+localStorage.token
                            }
                            initDictionaryList(params2).then(res=>{
                                sessionStorage.allDictData = JSON.stringify(res.data.data.list) ;
                            }).catch(err=>{
                                console.log(err);
                            });
                        }
                        _this.$router.go(-1);
                        // 这种设置 就算延迟执行，也不确定在延迟时间内，上面的异步请求是否已经完成，所以上面最好用同步请求获取数据
                        // setTimeout(function(){
                        //     _this.$router.go(-1);  // 登入时返回最后一次的路由  延迟执行
                        // },1000);
                    })
                    .catch(err=>{
                        console.log(err);
                    });
            }

        },
        mounted () {
            console.log(zuulHost+uamServer+clientID+authHost+tokenUri);
        }
    }
</script>

